const http = function ({ url, method = 'GET', data = {} } = option) {
  console.log(wx.getStorageSync('userIdEnc'))
  return new Promise((resolve, reject) => {
    console.log(data)
    if (!url) return reject('url 不能为空')

    wx.request({
      url: url, //仅为示例，并非真实的接口地址
      data: data,
      method: method,
      header: {
        'content-type': 'application/json', // 默认值
        token: '50a00a9b8d3402ed4f1b3ed4b890294b',
        uid: wx.getStorageSync('bol1').uid
      },
      success(res) {
        var bol1 = wx.getStorageSync('bol1')
        console.log(bol1)
        console.log('接口: ' + url)
        console.log(res.data.data.uid)
        if (res.data.data.uid !== undefined) {
          console.log(111)
          wx.setStorageSync('bol1', res.data.data) //将userIdEnc存入本地缓存
          console.log(bol1)
        }
        if (res.statusCode === 200) {
          resolve(res.data)
          console.log('222')
          if (bol1 == '') {
            console.log('333')
            if (res.data.error_code === 501 || res.data.error_code === 502) {
              console.log('111')
              wx.redirectTo({
                url: '/pages/logIn/logIn'
              })
              console.log(res.data)
            }
          }
        }
      },
      fail(err) {
        reject(err)
      }
    })
  })
}

module.exports = http
